<template>
  <div class="add-tag">
    <el-button type="primary" @click="addDialogVisible = true" size="mini"
      >添加标签</el-button
    >
  </div>
  <div class="tag">
    <el-table class="tag-table" :data="tagData" style="width: 560px">
      <el-table-column label="id" width="180" prop="id" />
      <el-table-column label="name" width="180" prop="name" />
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-popconfirm
            title="这个标签你确定要删除吗?"
            @confirm="handleDelete(scope.$index, scope.row)"
          >
            <template #reference>
              <el-button size="mini" type="danger">删除</el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <LJDialog title="编辑" :show="dialogFlag" @handleClose:show="handleClose">
      <el-form :mode="editData">
        <el-form-item
          class="white-item"
          v-for="(item, index) in editKey"
          :key="index"
          :label="item"
        >
          <el-input v-model="editData[item]" />
        </el-form-item>
      </el-form>
    </LJDialog>
    <addDialog
      @handleClose:show="handleAddDialogClose"
      :dialogVisible="addDialogVisible"
    />
  </div>
  <div class="center">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="count"
    >
    </el-pagination>
  </div>
</template>

<script>
import { ref } from "vue";
import LJDialog from "@/components/Dialog";
import addDialog from "./c-cpns/addDialog";
import { useTagsDataEffect, useEventEffect } from "./edit-hooks";
export default {
  components: {
    LJDialog,
    addDialog,
  },
  setup() {
    const { initTagsData } = useTagsDataEffect();
    const addDialogVisible = ref(false);
    const handleAddDialogClose = (data) => {
      if (data) {
        initTagsData();
      }
      addDialogVisible.value = false;
    };
    return {
      handleAddDialogClose,
      addDialogVisible,
      ...useTagsDataEffect(),
      ...useEventEffect(initTagsData),
    };
  },
};
</script>

<style lang="scss">
.center {
  padding-top: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.add-tag {
  margin-top: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.tag {
  display: flex;
  /* flex-direction: column; */
  align-items: center;
  justify-content: center;
  .tag-table {
    margin-top: 10rem;
  }
}
.white-item .el-form-item__label {
  color: #fff;
}
</style>